/**
 * 详情对话框
 */
var LabourModelCategoryInfoDlg = {
    data: {
        id: "",
        type: "",
        typeName: "",
        icons: "",
        sortNo: "",
        status: "",
        deleteFlag: "",
        createUser: "",
        createTime: "",
        updateUser: "",
        updateTime: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;


    //普通图片上传
    var upload = layui.upload;
    var filePath =new Array();
    upload.render({
        elem: '#urlImg'
        ,accept: 'images' //普通文件 images（图片）、file（所有文件）、video（视频）、audio（音频）
        ,exts: 'jpg|jpeg|png|docx|pdf' //只允许上传指定后缀的文件，一般结合 accept 参数类设定 jpg|png|gif|bmp|jpeg
        ,url: Changein.ctxPath + '/file/uploadFile' //统一上传接口，不用改
        ,data: {"moduleCode":"TEMPLATE","moduleName":"就创分类"}   //模块名称和编号需要到开发管理-字典管理-文件上传模块类型中设置
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#filePreview').attr('src', result); //图片链接（base64）
                $('#filePreview').css({"width":"100px","height":"100px"})
            });
        }
        ,done: function(res){
            if (res.code==200){
                Changein.success("文件上传成功！");
                filePath.push(res.data.src);
                $("#icons").val(res.data.src);

                layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', res.data.src);
            }else {
                Changein.error("文件上传失败！" + res.data.message,5000);
            }
        }
        ,error: function(){
            Changein.error("上传文件失败！");
        }
    });


    //获取详情信息，填充表单
    var ajax = new $ax(Changein.ctxPath + "/labourModelCategory/detail?id=" + Changein.getUrlParam("id"));
    var result = ajax.start();
    form.val('labourModelCategoryForm', result.data);
    var imgurl = Changein.ctxPath + result.data.urlImg;
    $('#filePreview').attr('src', imgurl);
    $('#filePreview').css({"width":"100px","height":"100px"})

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Changein.ctxPath + "/labourModelCategory/editItem", function (data) {
            Changein.success("更新成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Changein.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

});